package host.skiree.nettydemo.client.service.impl;

import host.skiree.nettydemo.client.service.MessageClientHandler;
import host.skiree.nettydemo.message.GroupMembersResponseMessage;
import host.skiree.nettydemo.message.Message;
import io.netty.channel.ChannelHandlerContext;

import java.util.Set;

/**
 * @author gcl
 * @date 2022/9/21 9:01
 */
public class GroupMembers implements MessageClientHandler {
    @Override
    public void handleMessage(ChannelHandlerContext ctx, Message message) {
        GroupMembersResponseMessage groupMembersResponseMessage = (GroupMembersResponseMessage) message;
        if ( groupMembersResponseMessage.isSuccess() ){
            Set<String> names = groupMembersResponseMessage.getMembers();
            String roomName = groupMembersResponseMessage.getRoomName();
            System.out.printf("聊天室 %s 中的成员 : %s\n",roomName, String.join(",", names));
        }else {
            System.out.println(groupMembersResponseMessage.getReason());
        }
    }
}
